package org.gluedom.data;

import static com.google.common.base.Preconditions.checkArgument;

import java.util.List;

import com.google.common.collect.ImmutableList;

public class Immutables {
	private Immutables() {
		throw new AssertionError();
	}

	public static <T> boolean isImmutable(Class<T> clazz) {
		if (Immutable.class.isAssignableFrom(clazz))
			return true;
		if (IMMUTABLE_JAVA.contains(clazz.getName()))
			return true;
		return false;
	}

	public static Object checkImmutable(Object object) {
		checkArgument(isImmutable(object.getClass()),
				"'%s' is not an immutable object", object.getClass());
		return object;
	}

	private static final List<String> IMMUTABLE_JAVA = ImmutableList
			.copyOf(new String[] { "java.lang.String", "java.lang.Byte",
					"java.lang.Short", "java.lang.Integer", "java.lang.Long",
					"java.lang.Double", "java.lang.Float", "java.lang.Boolean",
					"java.lang.Character" });
}
